import { ethers, JsonRpcProvider } from "ethers";
// import "../contracts/ContractAddress.js";
import fs from "fs";

import dotenv from "dotenv";
import { HOLYSTY_NET, SEPOLIA_NET } from "../contracts/ContractAddress.js";

dotenv.config("./.env");

export async function mint(to, uri) {
  const provider = new JsonRpcProvider(
    "https://sepolia.infura.io/v3/e6d75cb9f0b14aba8c7069ebefb03bbc"
  );
  const contractAddress = SEPOLIA_NET.erc721; //  your nft address

  const sign = new ethers.Wallet(process.env.PRIVATE_KEY_SEPOLIA, provider);
  //   console.log(sgin.address);

  const abi = JSON.parse(
    fs.readFileSync("./contracts/abi/nft.json").toString()
  );

  const contract = new ethers.Contract(contractAddress, abi, provider);

  const result = await contract.connect(sign).safeMint(to, uri);
  console.log(result.hash);
  const tokenId = await contract.totalSupply();
  return tokenId;
}

// mint("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", "examlp.com");
